import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    info: {
      name: '',
      role: '',
      avatar: ''
    }
  }),
  actions: {
    login(userInfo: { name: string; role: string; avatar?: string }) {
      this.info = {
        name: userInfo.name,
        role: userInfo.role,
        avatar: userInfo.avatar || ''
      }
    },
    logout() {
      this.info = {
        name: '',
        role: '',
        avatar: ''
      }
    }
  },
  persist: true // 自动持久化到localStorage
})